home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / pphlp / helpproc.pas < prev    next >
Pascal/Delphi Source File  |  1993-01-11  |  4KB  |  137 lines

  1. Program Help_processor (Input,Output) ;
  2.  
  3. {
  4.  
  5.  
  6. Program description: 
  7.  
  8.     Help pre-processor
  9.  
  10.  
  11. Author :                      Krish Singh
  12.  
  13. Written:                      8th Oct 1991
  14.  
  15. Version:                      1.0
  16.  
  17. Limitations: The program doesn't examine the contents of !<...|...>
  18. constructions, to see if there are any `...' within them.  Also, it seems
  19. impossible to include the string !<...|...> within the file it processes - this
  20. makes documenting the system itself rather difficult!
  21.  
  22. }
  23.  
  24. LABEL 
  25.     terminate;
  26. VAR
  27.     inchar,nextchar,outchar,dummychar :CHAR;
  28.     input_file,output_file,verbstring,
  29.     instring,outstring,boldon,boldoff: VARYING [132] OF CHAR;
  30.     i,istatus,il:integer;
  31.     infile,outfile:text;
  32.     bold,verbold:boolean;
  33.  
  34. FUNCTION 
  35. cli$get_value(com1:VARYING [a] OF CHAR;VAR com2:VARYING [b] OF CHAR;VAR i:integer):INTEGER;EXTERNAL;
  36.  
  37. {---------------------------------------------------------------------------}
  38. Begin {Main program}
  39.  
  40.     boldon:='E[1m';
  41.     boldoff:='E[0m';
  42.     boldon[1]:=chr(27);
  43.     boldoff[1]:=chr(27);
  44.     verbold:=true;
  45.  
  46.     istatus:=cli$get_value('INFILE',input_file,il);
  47.     { writeln('reading from ',input_file); }
  48.     istatus:=cli$get_value('OUTFILE',output_file,il);
  49.     { writeln('and writing to ',output_file); }
  50.  
  51.  
  52.     {
  53.     write('Input file>');
  54.     readln(input_file);
  55.  
  56.     write('Output file>');
  57.     readln(output_file);
  58.     }
  59.     
  60.     OPEN(infile,input_file,default:='.help',history:=old);
  61.     reset(infile);
  62.     OPEN(outfile,output_file,default:=input_file,history:=new); 
  63.     extend(outfile);
  64.  
  65.     writeln (outfile,'! File produced by PPhlp/Helpproc from input file ',
  66.     input_file);
  67.     
  68.     While not(eof(infile)) do
  69.     Begin
  70.         readln(infile,instring);
  71.  
  72.         IF ((length(instring)>0) and (instring[1]='!')) then begin
  73.         { It might be an instruction to this program.  In any case, }
  74.         { don't write it out to the output, as it would be ignored  }
  75.         { by the help librarian                        }
  76.  
  77.         IF (instring='!helpproc{stop}') then goto terminate;
  78.         IF (instring='!helpproc{verb_bold}') then verbold:=true;
  79.         IF (instring='!helpproc{verb_nobold}') then verbold:=false;
  80.  
  81.         IF (instring='!begin{verbatim}') and (verbold)
  82.                          then instring:=boldon;
  83.         IF (instring='!end{verbatim}')   and (verbold)
  84.                          then instring:=boldoff;
  85.         End
  86.  
  87.         Else Begin
  88.         { Check the line for special characters, writing it out as  }
  89.         { we go.                            }
  90.  
  91.         i:=1;
  92.         while (i<=length(instring)) do begin
  93.             inchar:=instring[i];
  94.             If (inchar<>'''') AND (inchar<>'`') AND (inchar<>'!') then begin
  95.             write(outfile,inchar);
  96.             End
  97.             Else begin
  98.  
  99.             IF (inchar='!') then begin
  100.                 nextchar:='Q';
  101.                 IF (i<>length(instring)) then nextchar:=instring[i+1];
  102.                 IF (nextchar='<') then begin
  103.                 while (instring[i]<>'|') AND (i<=length(instring)) do 
  104.                     begin 
  105.                     i:=i+1;
  106.                     End;
  107.                 i:=i+1;
  108.                 while (instring[i]<>'>') AND (i<=length(instring))
  109.                                 do begin
  110.                     write(outfile,instring[i]);
  111.                     i:=i+1;
  112.                 End;
  113.                 End
  114.                 Else begin
  115.                 write(outfile,inchar);
  116.                 End;
  117.             End;
  118.  
  119.             IF (inchar='`') then begin
  120.                 bold:=true;
  121.                 write(outfile,boldon);
  122.             End; 
  123.             IF (inchar='''') then begin
  124.                 IF not(bold) then write(outfile,'''');
  125.                 IF bold then write(outfile,boldoff);
  126.                 bold:=false;
  127.             End; 
  128.             End;
  129.             i:=i+1;
  130.         End { while (i<=length(instring)) };
  131.         writeln(outfile);
  132.         End;    { if (instring[1] = '!') }
  133.        End;
  134. terminate:       close(infile);close(outfile);
  135. End.  {Main program}
  136. {---------------------------------------------------------------------------}
  137.